package cc.mrbird.febs.buss.controller;

import cc.mrbird.febs.common.annotation.ControllerEndpoint;
import cc.mrbird.febs.common.utils.FebsUtil;
import cc.mrbird.febs.common.entity.FebsConstant;
import cc.mrbird.febs.common.controller.BaseController;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.buss.entity.Halldepart;
import cc.mrbird.febs.buss.service.IHalldepartService;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.HashMap;
import java.util.Enumeration;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;

/**
 *  Controller
 *
 * @author Lujingyuan
 * @date 2021-10-07 19:56:42
 */
@Slf4j
@Validated
@Controller
public class HalldepartController extends BaseController {

    @Autowired
    private IHalldepartService halldepartService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "halldepart")
    public String halldepartIndex(){
        return FebsUtil.view("halldepart/halldepart");
    }

    @GetMapping("halldepart")
    @ResponseBody
    @RequiresPermissions("halldepart:list")
    public FebsResponse getAllHalldeparts(Halldepart halldepart) {
        return new FebsResponse().success().data(halldepartService.findHalldeparts(halldepart));
    }

    @GetMapping("halldepart/list")
    @ResponseBody
    public FebsResponse halldepartList(QueryRequest request, HttpServletRequest req, Halldepart halldepart) {
        Enumeration enu=req.getParameterNames();
        HashMap<String,String> map=new HashMap<String,String>();
        while(enu.hasMoreElements()){
            String paraName=(String)enu.nextElement();
            map.put(paraName,req.getParameter(paraName));
        }
        Map<String, Object> dataTable = getDataTable(this.halldepartService.findHalldepartDetail(request, map));
        return new FebsResponse().success().data(dataTable);
    }

    @GetMapping("halldepart/data")
    @ResponseBody
    public FebsResponse halldepartData() {
        Map<String,Object> map=new HashMap<String,Object>();
        List<Halldepart> list= halldepartService.selectByMap(map);
        return new FebsResponse().success().data(list);
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "halldepart/add")
    public String goHalldepartAdd() {
        return FebsUtil.view("halldepart/halldepartAdd");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "halldepart/update/{id}")
    public String goHalldepartUpdate(@PathVariable String id, Model model) {
        Halldepart obj= halldepartService.getById(id);
        model.addAttribute("obj",obj);
        return FebsUtil.view("halldepart/halldepartUpdate");
    }

    @ControllerEndpoint(operation = "新增Halldepart", exceptionMessage = "新增Halldepart失败")
    @PostMapping("halldepart")
    @ResponseBody
    public FebsResponse addHalldepart(@Valid Halldepart halldepart) {
        this.halldepartService.add(halldepart);
        return new FebsResponse().success();
    }

    @GetMapping("halldepart/delete/{objIds}")
    @ControllerEndpoint(operation = "删除", exceptionMessage = "删除失败")
    @ResponseBody
    public FebsResponse deleteHalldepart( @PathVariable String objIds) {
        String[] ids = objIds.split(StringPool.COMMA);
        this.halldepartService.deleteHalldepart(ids);
        return new FebsResponse().success();
    }

    @ControllerEndpoint(operation = "修改Halldepart", exceptionMessage = "修改Halldepart失败")
    @PostMapping("halldepart/update")
    @ResponseBody
    public FebsResponse updateHalldepart(Halldepart halldepart) {
        this.halldepartService.updateHalldepart(halldepart);
        return new FebsResponse().success();
    }
}
